package com.vincent.resource.controller;

import com.alibaba.fastjson.JSONObject;
import com.vincent.core.vo.Msg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

@RestController
@RequestMapping("/configInfo")
@Slf4j
public class ConfigInfoController {

    @GetMapping("/list")
    public Msg listAll(@RequestParam int pageIndex, @RequestParam int pageSize,
                       @RequestParam(required = false, defaultValue = "") String configId){
        log.info("listAll index={}, size={}, configId={}", pageIndex, pageSize, configId );
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("pageTotal",20);
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Map<String, Object> map =  new HashMap<>();
            map.put("resourceId", "res-"+UUID.randomUUID().toString());
            map.put("resourceName", "测试资源-"+UUID.randomUUID().toString());
            map.put("state", 1);
            map.put("type", "MatrixService");
            map.put("updateDate", "2020-01-20 10:42:36");
            list.add(map);

        }
        jsonObject.put("tableData",list);
        return Msg.success(jsonObject);
    }


    @GetMapping("/get")
    public Msg get(@RequestParam String configId) {
        log.info("get -> {}", configId);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", UUID.randomUUID().toString());
        jsonObject.put("configId",configId);
        jsonObject.put("type","MatrixService");
        jsonObject.put("state",1);
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            Map<String, Object> map =  new HashMap<>();
            map.put("key", "key-"+i);
            map.put("value", "value-"+i);
            list.add(map);

        }
        jsonObject.put("metaData",list);
        return Msg.success(jsonObject);
    }


    @PostMapping("/update")
    public Msg update(@RequestBody JSONObject info) {
        log.info("update -> {}", info.toJSONString());
        return Msg.success();
    }


    @PostMapping("/add")
    public Msg add(@RequestBody JSONObject info) {
        log.info("add -> {}", info.toJSONString());
        return Msg.success();
    }


    @PostMapping("/delete")
    public Msg delete(@RequestParam String configId) {
        log.info("delete -> {}", configId);
        return Msg.success();
    }
}
